package com.parking.bang.rpc.core.client;

import java.lang.reflect.Method;
import java.util.UUID;

import com.google.common.reflect.AbstractInvocationHandler;
import com.parking.bang.rpc.model.ReqMessage;

/**
 * send proxy
 * 
 * @author ivan
 *
 * @param <T>
 */
public class MessageSendProxy<T> extends AbstractInvocationHandler {

	@Override
	protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
		ReqMessage request = new ReqMessage();
		request.setMessId(UUID.randomUUID().toString());
		request.setClzName(method.getDeclaringClass().getName());
		request.setMethodName(method.getName());
		request.setTypeParas(method.getParameterTypes());
		request.setParas(args);

		MessageSendHandler handler = RPCServerLoader.getInstance().getMessageSendHandler();
		MessageSendCallback callBack = handler.sendRequest(request);
		return callBack.start();
	}

}
